package br.com.toscano.gobra.business;

import java.util.List;

import br.com.toscano.gobra.domain.Configuracao;
import br.com.toscano.gobra.persistence.ConfiguracaoDAO;
import br.gov.frameworkdemoiselle.lifecycle.Startup;
import br.gov.frameworkdemoiselle.stereotype.BusinessController;
import br.gov.frameworkdemoiselle.template.DelegateCrud;
import br.gov.frameworkdemoiselle.transaction.Transactional;

@BusinessController
public class ConfiguracaoBC extends DelegateCrud<Configuracao, Long, ConfiguracaoDAO> {
	
	private static final long serialVersionUID = 1L;
	
	private static Configuracao configuacao;
	
	@Startup
	@Transactional
	public void load() {
		List<Configuracao> listaConfiguracao = findAll();
		if (listaConfiguracao != null && !listaConfiguracao.isEmpty()) {
			configuacao = listaConfiguracao.iterator().next(); 
			
		}
	}

	public static Configuracao getConfiguacao() {
		return configuacao;
	}

	@Override
	public Configuracao insert(Configuracao bean) {

		configuacao = super.insert(bean);
		
		return configuacao;
	}

	@Override
	public Configuracao update(Configuracao bean) {
		configuacao = super.update(bean);
		
		return configuacao;
	}
}